package soulkun.library.utils.toast

import android.os.Handler
import android.widget.Toast
import soulkun.library.LibraryInit

object ToastUtils {

    private var toast: Toast? = null

    fun show(msg: String) {
        show(msg, 1000)
    }

    fun show(msg: String, time: Long) {
        if (toast != null) {
            toast?.cancel()
            toast = null
        }
        toast = Toast.makeText(LibraryInit.context, msg, Toast.LENGTH_LONG)
        toast?.show()
        if (time >= 3500) return
        val handler = Handler()
        handler.postDelayed({toast?.cancel() }, time)
    }

}